package com.eu.controller;

import com.eu.ebpm.engine.init.EbpmInitialization;
import com.eu.ebpm.engine.service.DeployService;
import com.eu.ebpm.engine.service.ExecutionService;
import com.eu.ebpm.engine.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 云路供应链科技有限公司 版权所有  Copyright 2019
 *
 * @author wangxiaohua
 * @since Created in 2019-11-04 14:11
 */
@RestController
public class TestController {

    public static Map<String, User> usersCache = new HashMap<String, User>();

    static {
        User u1 = new User("陈勇楷", "金胖子", "唐老板", "level1", "新宇");
        User u2 = new User("陈楷",     "金胖子", "唐老板", "level3", "新宇");
        User u3 = new User("金胖子",     "李鹏", "唐老板", "level5", "新宇");

        User u4 = new User("康师傅", "郑老大", "唐老板", "level2", "新宇");
        User u5 = new User("郑老大", "李德明", "唐老板", "level5", "新宇");

        User u6 = new User("李鹏",     "唐老板", "唐老板", "level6", "新宇");
        User u7 = new User("李德明", "唐老板", "唐老板", "level6", "新宇");

        User u8 = new User("吴静",     "李德明", "唐老板", "kaoqin", "新宇");
        User u9 = new User("唐老板", "唐老板", "唐老板", "level8", "新宇");

        usersCache.put(u1.getName(), u1);
        usersCache.put(u2.getName(), u2);
        usersCache.put(u3.getName(), u3);
        usersCache.put(u4.getName(), u4);
        usersCache.put(u5.getName(), u5);
        usersCache.put(u6.getName(), u6);
        usersCache.put(u7.getName(), u7);
        usersCache.put(u8.getName(), u8);
        usersCache.put(u9.getName(), u9);
    }

    @Autowired
    private TaskService taskService;

    @Autowired
    private DeployService deployService;

    @Autowired
    private ExecutionService executionService;

    @Autowired
    private EbpmInitialization definitionsInitialization;

    String str = "<Definitions key=\"AskForLeave\" desc=\"请假流程\">\n" +
            "\t<UserTask id=\"mission274341\" name=\"请假申请\" candidateGroups=\"user\" />\n" +
            "\t<SequenceFlow id=\"Line1708250925314\" desc=\"申请\" sourceRef=\"mission274341\" targetRef=\"UserTask1708250924253\" >\n" +
            "\t\t<Express><![CDATA[]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<UserTask id=\"mission277962\" name=\"经理审批\" assignee=\"#userQuery.getHigherLevel(#executionUser)\" />\n" +
            "\t<SequenceFlow id=\"Line1708250927457\" desc=\"驳回:'起草节点'(返回本人)\" sourceRef=\"mission277962\" targetRef=\"mission274341\" >\n" +
            "\t\t<Express><![CDATA[manager='no']]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<SequenceFlow id=\"2017082310071910\" desc=\"同意\" sourceRef=\"mission277962\" targetRef=\"201708231007069\" >\n" +
            "\t\t<Express><![CDATA[manager='yes']]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<StartEvent id=\"mission275037\" name=\"开始\" />\n" +
            "\t<SequenceFlow id=\"line277478\" sourceRef=\"mission275037\" targetRef=\"mission274341\" >\n" +
            "\t\t<Express><![CDATA[]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<EndEvent id=\"mission279729\" name=\"结束\" />\n" +
            "\t<UserTask id=\"201708231007069\" name=\"老板审批\" assignee=\"#userQuery.getBossLevel(#executionUser)\" />\n" +
            "\t<SequenceFlow id=\"2017082310090212\" desc=\"驳回:'起草节点'(返回本人)\" sourceRef=\"201708231007069\" targetRef=\"mission274341\" >\n" +
            "\t\t<Express><![CDATA[!yes]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<SequenceFlow id=\"2017082310072811\" desc=\"同意\" sourceRef=\"201708231007069\" targetRef=\"mission279729\" >\n" +
            "\t\t<Express><![CDATA[yes]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<UserTask id=\"UserTask1708250924253\" name=\"考勤员审核\" candidateUsers=\"吴静\" candidateGroups=\"kaoqin\" />\n" +
            "\t<SequenceFlow id=\"Line1708250926426\" desc=\"驳回\" sourceRef=\"UserTask1708250924253\" targetRef=\"mission274341\" >\n" +
            "\t\t<Express><![CDATA[no]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "\t<SequenceFlow id=\"Line1708250925505\" desc=\"同意\" sourceRef=\"UserTask1708250924253\" targetRef=\"mission277962\" >\n" +
            "\t\t<Express><![CDATA[yes]]></Express>\n" +
            "\t</SequenceFlow>\n" +
            "</Definitions>\n" +
            "\n" +
            "<Position>\n" +
            "\t<UserTask id=\"mission274341\" x=\"204\" y=\"158\" w=\"120\" h=\"50\" />\n" +
            "\t<SequenceFlow id=\"Line1708250925314\" type=\"RTLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"6\" resizeToExtraX=\"-18\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"-53\" distanceHeight=\"-89\" />\n" +
            "\t<UserTask id=\"mission277962\" x=\"204\" y=\"377\" w=\"120\" h=\"50\" />\n" +
            "\t<SequenceFlow id=\"Line1708250927457\" type=\"TDLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"-44\" distanceHeight=\"61\" />\n" +
            "\t<SequenceFlow id=\"2017082310071910\" type=\"DTLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"9\" distanceHeight=\"-45\" />\n" +
            "\t<StartEvent id=\"mission275037\" x=\"235\" y=\"51\" w=\"58\" h=\"58\" />\n" +
            "\t<SequenceFlow id=\"line277478\" type=\"DTLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"0\" distanceHeight=\"0\" />\n" +
            "\t<EndEvent id=\"mission279729\" x=\"235\" y=\"574\" w=\"58\" h=\"58\" />\n" +
            "\t<UserTask id=\"201708231007069\" x=\"204\" y=\"483\" w=\"120\" h=\"50\" />\n" +
            "\t<SequenceFlow id=\"2017082310090212\" type=\"LLLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"-176\" distanceHeight=\"87\" />\n" +
            "\t<SequenceFlow id=\"2017082310072811\" type=\"DTLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"6\" distanceHeight=\"-42\" />\n" +
            "\t<UserTask id=\"UserTask1708250924253\" x=\"386\" y=\"273\" w=\"134\" h=\"50\" />\n" +
            "\t<SequenceFlow id=\"Line1708250926426\" type=\"TRLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"-5\" resizeMiddleExtra=\"0\" distanceWidth=\"56\" distanceHeight=\"-22\" />\n" +
            "\t<SequenceFlow id=\"Line1708250925505\" type=\"DRLine\" resizeFromExtraX=\"0\" resizeFromExtraY=\"0\" resizeToExtraX=\"0\" resizeToExtraY=\"0\" resizeMiddleExtra=\"0\" distanceWidth=\"52\" distanceHeight=\"-27\" />\n" +
            "</Position>\n" +
            "\n" +
            "<TaskJson>\n" +
            "<![CDATA[\n" +
            "[{\"type\":\"UserTask\", \"mission\":\"mission274341\",\"x\":204,\"y\":158,\"w\":120,\"h\":50, \"desc\":\"请假申请\"},{\"type\":\"UserTask\", \"mission\":\"mission277962\",\"x\":204,\"y\":377,\"w\":120,\"h\":50, \"desc\":\"经理审批\"},{\"type\":\"StartEvent\", \"mission\":\"mission275037\",\"x\":235,\"y\":51,\"w\":58,\"h\":58, \"desc\":\"开始\"},{\"type\":\"EndEvent\", \"mission\":\"mission279729\",\"x\":235,\"y\":574,\"w\":58,\"h\":58, \"desc\":\"结束\"},{\"type\":\"UserTask\", \"mission\":\"201708231007069\",\"x\":204,\"y\":483,\"w\":120,\"h\":50, \"desc\":\"老板审批\"},{\"type\":\"UserTask\", \"mission\":\"UserTask1708250924253\",\"x\":386,\"y\":273,\"w\":134,\"h\":50, \"desc\":\"考勤员审核\"}]\n" +
            "]]>\n" +
            "</TaskJson>\n" +
            "\n" +
            "<LineJson>\n" +
            "<![CDATA[\n" +
            "[{\"type\":\"RTLine\",\"name\":\"Line1708250925314\",\"x1\":318,\"y1\":189,\"x2\":435,\"y2\":189,\"x3\":435,\"y3\":279,\"desc\":\"申请\",\"lx\":382,\"ly\":190},{\"type\":\"TDLine\",\"name\":\"Line1708250927457\",\"x1\":264,\"y1\":383,\"x2\":264,\"y2\":292.5,\"x3\":264,\"y3\":292.5,\"x4\":264,\"y4\":202,\"desc\":\"驳回:'起草节点'(返回本人)\",\"lx\":220,\"ly\":263},{\"type\":\"DTLine\",\"name\":\"2017082310071910\",\"x1\":264,\"y1\":421,\"x2\":264,\"y2\":455,\"x3\":264,\"y3\":455,\"x4\":264,\"y4\":489,\"desc\":\"同意\",\"lx\":273,\"ly\":444},{\"type\":\"DTLine\",\"name\":\"line277478\",\"x1\":264,\"y1\":103,\"x2\":264,\"y2\":133.5,\"x3\":264,\"y3\":133.5,\"x4\":264,\"y4\":164,\"desc\":\"\",\"lx\":214,\"ly\":127},{\"type\":\"LLLine\",\"name\":\"2017082310090212\",\"x1\":210,\"y1\":508,\"x2\":174,\"y2\":508,\"x3\":174,\"y3\":183,\"x4\":210,\"y4\":183,\"desc\":\"驳回:'起草节点'(返回本人)\",\"lx\":34,\"ly\":270},{\"type\":\"DTLine\",\"name\":\"2017082310072811\",\"x1\":264,\"y1\":527,\"x2\":264,\"y2\":553.5,\"x3\":264,\"y3\":553.5,\"x4\":264,\"y4\":580,\"desc\":\"同意\",\"lx\":270,\"ly\":538},{\"type\":\"TRLine\",\"name\":\"Line1708250926426\",\"x1\":453,\"y1\":279,\"x2\":453,\"y2\":178,\"x3\":318,\"y3\":178,\"desc\":\"驳回\",\"lx\":374,\"ly\":156},{\"type\":\"DRLine\",\"name\":\"Line1708250925505\",\"x1\":453,\"y1\":317,\"x2\":453,\"y2\":402,\"x3\":318,\"y3\":402,\"desc\":\"同意\",\"lx\":370,\"ly\":375}]\n" +
            "]]>\n" +
            "</LineJson>";

    @RequestMapping("/test1")
    public String test1() throws Exception {
        deployService.deploy(str);

        definitionsInitialization.init();
        return "test1";
    }

    public static void main(String[] args) {
        String[] truncateSqls = "TRUNCATE TABLE WF_DE_DEPLOY,TRUNCATE TABLE WF_DE_MISSION,TRUNCATE TABLE WF_DE_POSITION,TRUNCATE TABLE WF_DE_TRANSFER,TRUNCATE TABLE WF_HI_EXE_VARIABLE,TRUNCATE TABLE WF_HI_EXECUTION,TRUNCATE TABLE WF_HI_FORKVARIABLE,TRUNCATE TABLE WF_HI_TASK,TRUNCATE TABLE WF_HI_TASK_VARIABLE,TRUNCATE TABLE WF_RU_EXE_VARIABLE,TRUNCATE TABLE WF_RU_EXECUTION,TRUNCATE TABLE WF_RU_FORKVARIABLE,TRUNCATE TABLE WF_RU_TASK,TRUNCATE TABLE WF_RU_TASKIDENTITY".split(",");
        for (String str : truncateSqls) {
            System.out.println(str + ";");
        }
    }
}
